1. #include <avr/io.h>
  2. #include <util/delay.h>
  3. #include <avr/interrupt.h>
  4. /******************************************************************************/
  5. int main(void)
  6. {
  7. cli();
  8. DDRD &= ~_BV(DDD0); // set as input
  9. PORTD |= _BV(PORTD0); // enable pull-up
  10. DDRB |= _BV(DDD5);
  11. PORTB |= _BV(PORTB5); // initialize to high
  12. PCICR |= _BV(PCIE2); // set PCIE2 to enable PCMSK2 scan
  13. PCMSK2 |= _BV(PCINT16); // set PCINT16 to trigger an interrupt on state change
  14. sei(); // turn on interrupts
  15. while (1);
  16. }
  17. /******************************************************************************/
  18. ISR (PCINT2_vect)
  19. {
  20. if (PIND & _BV(DDD0))
  21. PORTB |= _BV(PORTB5);
  22. else
  23. PORTB &= ~_BV(PORTB5);
  24. }
  25. /******************************************************************************/